﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using Model;
using Util;


namespace BLL
{
   public class BllFunctions:Bll<tb_functions>
    {
        public BllFunctions() { }
        public BllFunctions(Page _page) : base(_page) { }
        public BllFunctions(Dal<tb_functions> _dal) : base(_dal) { }
        public BllFunctions(Page _page, Dal<tb_functions> _dal) : base(_page, _dal) { }

        public override bool Check(tb_functions entity)
        {
            return true;
        }

        public IList<tb_functions> GetTopCatalog()
        {
            return GetList(c => c.parentId == 0, true, c => c.sort);
        }

        public IList<tb_functions> GetSubCatalog(int id)
        {
            return GetList(c => c.parentId == id, true, c => c.sort);
        }

        public string HtmlFunctions()
        {
            string html = "";
            var toplist = GetTopCatalog();
            foreach (var topitem in toplist)
            {
                html += "<h1 class='type'><a href='javascript:void(0)'>" + topitem.name + "</a></h1>";
                html += "<div class='content'>";
                html += "<table width='100%' border='0' cellspacing='0' cellpadding='0' style='margin: 0px; padding: 0px;'><tr><td><img src='images/menu_topline.gif' width='182' height='3' /></td></tr></table>";
                html += "<ul class='MM'>";
                var sublist = GetSubCatalog(topitem.id);
                foreach (var subitem in sublist)
                {
                    html += "<li><a href='" + subitem.link + "' target='main'>" + subitem.name + "</a></li>";
                }
                html += "</ul></div>";
            }
            return html;
        }
    }
}
